<template>
	<view>
		<view class="search_area">
			<u-search placeholder="搜索" :showAction="false" bgColor="#EEF4FA" v-model="policyForm.projectName"
				@change="search()" @clear="clear"></u-search>
		</view>
		<!-- <view class="classify_area around_layout">
			<view v-for="(item,index) in list1" :key="index" class="start_layout classify_item"
				@click="changeIndex(index)">
				{{item.name.length>4?item.name.substr(0,4)+'...':item.name,}}
				<view class="cuIcon-unfold"></view>
			</view>
		</view> -->
		<view class="padding">
			<approveList v-if="entryStatus==2||entryStatus==3" :listData='dataList' :entryStatus="entryStatus">
			</approveList>
			<allList showAuditState v-else :listData='dataList' :entryStatus="entryStatus"></allList>
		</view>
		<u-back-top :scroll-top="scrollTop"></u-back-top>
		<u-loadmore v-show="dataList.length>0" :status="status" />
		<u-picker v-if="showPicker" @cancel="showPicker=false" @confirm="confirmPicker" :show="showPicker"
			:columns="columns" :keyName="keyName"></u-picker>
	</view>
</template>

<script>
	import {
		listProjectInfo,
		listApproveProject,
		getDicts,
		listMultiDict
	} from '@/utils/api.js'
	export default {
		data() {
			return {
				entryStatus: null,
				show: false,
				showPicker: false,
				columns: [],
				siftType: '',
				keyName: 'dictLabel',
				policyForm: {
					pageNum: 1,
					pageSize: 10,
					projectName: "",
					industryCategory: "",
					industryTypeOne: "",
					industrialChain: ""
				},
				status: 'nomore',
				total: 0,
				dataList: [],
				list1: [{
					name: '产业分类',
					index: 0,
					list: [],
					label: 'industryCategory'
				}, {
					name: '行业分类',
					index: 1,
					list: [],
					label: 'industryTypeOne'
				}, {
					name: '产业链',
					index: 2,
					list: [],
					label: 'industrialChain'
				}],
				scrollTop: 0
			}
		},
		onLoad(option) {
			uni.setNavigationBarTitle({
				title: option.title
			});
			this.entryStatus = parseInt(option.entryStatus)
			this.getDict()
		},
		onShow() {
			this.search()
		},
		onReachBottom() {
			if (this.policyForm.pageNum >= this.total / 10) {
				this.status = 'nomore'
				return
			} else {
				this.status = 'loading'
				this.policyForm.pageNum++
				this.init()
			}
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		methods: {
			getDict() {
				//产业类别
				getDicts('cylb').then(res => {
					res.data.unshift({
						dictLabel: "全部",
						dictValue: ''
					})
					this.list1[0].list = res.data
				})
				//产业链
				getDicts('cyl').then(res => {
					res.data.unshift({
						dictLabel: "全部",
						dictValue: ''
					})
					this.list1[2].list = res.data
				})
				//获取一级行业
				listMultiDict('1783481533278810114').then(res => {
					res.data.unshift({
						dictName: "全部",
						baseId: ''
					})
					this.list1[1].list = res.data
				})
			},
			init() {
				uni.showLoading({
					title: '加载中'
				});
				if (this.entryStatus == 2 || this.entryStatus == 3) {
					this.policyForm.entryStatus = this.entryStatus
					this.policyForm.state = 0
					listApproveProject(this.policyForm).then(response => {
						if (response.code == 200) {
							uni.hideLoading();
							this.dataList = [...this.dataList, ...response.rows]
							this.total = response.total
						} else {
							uni.hideLoading();
							uni.showToast({
								title: response.msg,
								icon: 'none',
								duration: 3000
							})
						}
						this.status = 'nomore'
					});
				} else {
					this.policyForm.entryStatus = this.entryStatus != 0 ? this.entryStatus : null
					this.policyForm.state = 0
					listProjectInfo(this.policyForm).then(response => {
						if (response.code == 200) {
							uni.hideLoading();
							this.dataList = [...this.dataList, ...response.rows]
							this.total = response.total
						} else {
							uni.hideLoading();
							uni.showToast({
								title: response.msg,
								icon: 'none',
								duration: 3000
							})
						}
						this.status = 'nomore'
					});
				}
			},
			//点击上方筛选
			changeIndex(index) {
				this.siftType = index
				if (index == 1) {
					this.keyName = 'dictName'
				} else {
					this.keyName = 'dictLabel'
				}
				this.columns = []
				this.columns.push(this.list1[this.siftType].list)
				this.showPicker = true
			},
			confirmPicker(e) {
				if (this.siftType == 0) {
					if (e.value[0].dictLabel == '全部') {
						this.policyForm.industryCategory = ''
						this.list1[this.siftType].name = '产业分类'
					} else {
						this.policyForm.industryCategory = e.value[0].dictValue
						this.list1[this.siftType].name = e.value[0].dictLabel
					}
				}
				if (this.siftType == 2) {
					if (e.value[0].dictLabel == '全部') {
						this.policyForm.industrialChain = ''
						this.list1[this.siftType].name = '产业链'
					} else {
						this.policyForm.industrialChain = e.value[0].dictValue
						this.list1[this.siftType].name = e.value[0].dictLabel
					}
				}
				if (this.siftType == 1) {
					if (e.value[0].dictName == '全部') {
						this.policyForm.industryTypeOne = ''
						this.list1[this.siftType].name = '行业分类'
					} else {
						this.policyForm.industryTypeOne = e.value[0].baseId
						this.list1[this.siftType].name = e.value[0].dictName
					}
				}
				this.showPicker = false
				this.search()
			},
			search() {
				this.policyForm.pageNum = 1
				this.dataList = []
				this.init()
			},
			clear() {
				this.policyForm.projectName = ""
				this.search()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.search_area {
		padding: 10rpx 24rpx;
		background: #FFFFFF;
	}

	.classify_area {
		padding: 24rpx;
		background: #FFFFFF;

		.classify_item {
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #303946;
		}

		.active {
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: 600;
			color: #1569E6;
		}

		.sift {
			width: 36rpx;
			height: 36rpx;
		}
	}

	.btn-selected {
		background: #3389FF;
		border-radius: 10rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 30rpx;
		color: #FFFFFF;
		padding: 19rpx;
		margin-bottom: 30rpx;
	}
</style>